<?php
/*
Plugin Name: Footer Notes
Plugin URI: http://notesblog.com/footer-notes/
Description: Footer Notes adds a simple code block to your posts and feeds.
Version: 0.1
Author: Thord Daniel Hedengren
Author URI: http://tdhedengren.com
*/
// add menu to admin --
if (is_admin()){
	add_action('admin_menu', 'nb_footernotes_menu');
	add_action('admin_init', 'nb_footernotes_register');
}

// whitelist options --
function nb_footernotes_register() {
	register_setting('nb_footernotes_optiongroup', 'nbfn_post');
	register_setting('nb_footernotes_optiongroup', 'nbfn_feed');
}

// admin menu page details --
function nb_footernotes_menu() {
	add_options_page('Footer Notes Settings', 'Footer Notes', 8, 'nb_footernotes', 'nb_footernotes_
	options');
}

// add actual menu page --
function nb_footernotes_options() { ?>
	<div class="wrap">
		<div id="icon-options-general" class="icon32"><br /></div>
		<h2>Footer Notes</h2>
		<p>This is the settings page for the <a href="http://notesblog.com/footer-notes/">Footer Notes</a> plugin. This plugin adds HTML code at the bottom of your posts and your feed items. Just add the HTML code you want for the two possible spots.</p>
		<p>Leave either of these <strong>completely empty</strong> if you do not want to return anything!</p>
		
		<form method="post" action="options.php">
		<?php settings_fi elds('nb_footernotes_optiongroup'); ?>
		
		<table class="form-table" style="margin-top: 20px; padding-bottom: 10px; border: 1px dotted #bbb; border-width:1px 0;">
			<tr valign="top">
				<th scope="row">
					<h3 style="margin-top: 10px;">Code to be added after posts</h3>
					<p>The code below will be added where you put the <code>nb_footernotes() </code> template tag in your theme, on a per-post basis. It needs to be within the loop.</p>
				</th>
			</tr><tr>
				<td><textarea name="nbfn_post" style="width: 90%; height: 150px; padding: 10px;"><?php echo get_option('nbfn_post'); ?></textarea></td>
			</tr><tr valign="top">
				<th scope="row">
					<h3 style="margin-top: 10px;">Code to be added after feed items</h3>
					<p>The code below will be added at the bottom of each item in your feeds.</p>
				</th>
			</tr><tr>
				<td><textarea name="nbfn_feed" style="width: 90%; height: 150px; padding: 10px;"><?php echo get_option('nbfn_feed'); ?></textarea></td>
			</tr>
		</table>
	
		<p class="submit">
			<input type="submit" class="button-primary" value="Save Changes" />
		</p>
	
		</form>
	</div>
<?php }
// custom hook for the posts --
function nb_footernotes() {
	do_action('nb_footernotes');
}
// and now for the post output --
add_action('nb_footernotes', 'nb_footernotes_post_output');
function nb_footernotes_post_output() {
	echo get_option('nbfn_post');
}
// feed output time --
function nb_footernotes_rss() {
	echo get_option('nbfn_feed');
}
// feed fi lters --
add_fi lter('the_excerpt_rss', 'nb_footernotes_rss');
add_fi lter('the_content_rss', 'nb_footernotes_rss');
// that's it! -- FIN//
?>